<template>
  <div>
    <h1>人员列表</h1>
    <h3 style="color: red">求和为：{{sum}}</h3>
    <input type="text" placeholder="请输入名字" v-model="name">
    <button @click="addPerson(name)">添加</button>
    <ul>
      <li v-for="p in people" :key="p.id">{{ p.name }}</li>
    </ul>
  </div>
</template>

<script>
import {mapState, mapGetters, mapMutations, mapActions} from 'vuex';
import {nanoid} from "nanoid";


export default {
  name: "PersonList",
  data() {
    return {
      name: ''
    }
  },
  props: [],
  computed: {
    ...mapState(['people','sum']),
  },
  components: {},
  methods: {
    addPerson(name) {
      if (name.trim() !== '') {
        // this.people.push({id: nanoid(), name: name});
        this.$store.commit('addPerson', {id: nanoid(), name: name});
        this.name = '';
      }
    },
  },
  mixins: [],
  watch: {},
  filters: {},
  directives: {}
}
</script>

<style scoped>

</style>